package com.video.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.video.common.annotation.Log;
import com.video.common.enums.BusinessType;
import com.video.system.domain.VideoTeacherTitle;
import com.video.system.service.IVideoTeacherTitleService;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 职称Controller
 * 
 * @author lyh
 * @date 2021-07-20
 */
@Controller
@RequestMapping("/system/title")
public class VideoTeacherTitleController extends BaseController
{
    private String prefix = "system/title";

    @Autowired
    private IVideoTeacherTitleService videoTeacherTitleService;

    @RequiresPermissions("system:title:view")
    @GetMapping()
    public String title()
    {
        return prefix + "/title";
    }

    /**
     * 查询职称列表
     */
    @RequiresPermissions("system:title:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VideoTeacherTitle videoTeacherTitle)
    {
        startPage();
        List<VideoTeacherTitle> list = videoTeacherTitleService.selectVideoTeacherTitleList(videoTeacherTitle);
        return getDataTable(list);
    }

    /**
     * 导出职称列表
     */
    @RequiresPermissions("system:title:export")
    @Log(title = "职称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VideoTeacherTitle videoTeacherTitle)
    {
        List<VideoTeacherTitle> list = videoTeacherTitleService.selectVideoTeacherTitleList(videoTeacherTitle);
        ExcelUtil<VideoTeacherTitle> util = new ExcelUtil<VideoTeacherTitle>(VideoTeacherTitle.class);
        return util.exportExcel(list, "职称数据");
    }

    /**
     * 新增职称
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存职称
     */
    @RequiresPermissions("system:title:add")
    @Log(title = "职称", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VideoTeacherTitle videoTeacherTitle)
    {
        return toAjax(videoTeacherTitleService.insertVideoTeacherTitle(videoTeacherTitle));
    }

    /**
     * 修改职称
     */
    @GetMapping("/edit/{titleId}")
    public String edit(@PathVariable("titleId") Integer titleId, ModelMap mmap)
    {
        VideoTeacherTitle videoTeacherTitle = videoTeacherTitleService.selectVideoTeacherTitleById(titleId);
        mmap.put("videoTeacherTitle", videoTeacherTitle);
        return prefix + "/edit";
    }

    /**
     * 修改保存职称
     */
    @RequiresPermissions("system:title:edit")
    @Log(title = "职称", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VideoTeacherTitle videoTeacherTitle)
    {
        return toAjax(videoTeacherTitleService.updateVideoTeacherTitle(videoTeacherTitle));
    }

    /**
     * 删除职称
     */
    @RequiresPermissions("system:title:remove")
    @Log(title = "职称", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(videoTeacherTitleService.deleteVideoTeacherTitleByIds(ids));
    }
}
